﻿using System;
using System.Windows.Forms;
using AppAcc.Models;

namespace AppAcc.Views.DanhMuc
{
    public partial class FormNhanVienThem : DevComponents.DotNetBar.RibbonForm
    {
        //private AppAccContext db = new AppAccContext();
        private PhanMenKeToanEntities1 db = new PhanMenKeToanEntities1();
        public FormNhanVienThem()
        {
            InitializeComponent();
        }
        private void FormNhanVienThem_Load(object sender, EventArgs e)
        {
            KiemTraTrangThai();
        }

        private void txtTenNhanVien_TextChanged(object sender, EventArgs e)
        {
            KiemTraTrangThai();
        }

        private void txtChucVu_TextChanged_1(object sender, EventArgs e)
        {
            KiemTraTrangThai();
        }

        private void txtDienThoai_TextChanged(object sender, EventArgs e)
        {
            KiemTraTrangThai();
        }

        private void txtTaiKhoanNganHang_TextChanged(object sender, EventArgs e)
        {
            KiemTraTrangThai();
        }

        private void txtMaSoThue_TextChanged(object sender, EventArgs e)
        {
            KiemTraTrangThai();
        }

        private void txtDiaChi_TextChanged(object sender, EventArgs e)
        {
            KiemTraTrangThai();
        }

        private void BttLuu_Click(object sender, EventArgs e)
        {
            Create();
        }

        private void BttThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        void KiemTraTrangThai()
        {
            if (txtDienThoai.Text != "" && txtChucVu.Text != "" && txtDiaChi.Text != "" && txtMaSoThue.Text != "" && txtTenNhanVien.Text != "" && txtTaiKhoanNganHang.Text!="")
            {
                BttLuu.Enabled = true;
            }
            else
            {
                BttLuu.Enabled = false;
            }
        }

        void Create()
        {
            try
            {
                var t = new NhanVien();
                t.TenNhanVien = txtTenNhanVien.Text;
                t.ChucVu = txtChucVu.Text;
                t.MaSoThue = txtMaSoThue.Text;
                t.TaiKhoanNganHang = txtTaiKhoanNganHang.Text;
                t.DiaChi = txtDiaChi.Text;
                t.DienGiai = txtDienGiai.Text;
                t.DienThoai= txtDienThoai.Text;
                db.NhanViens.Add(t);
                db.SaveChanges();
                MessageBox.Show("Thêm mới thành công!");
                Reset();

            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

        void Reset()
        {
            txtMaSoThue.Text = "";
            txtChucVu.Text = "";
            txtDiaChi.Text = "";
            txtDienGiai.Text = "";
            txtTaiKhoanNganHang.Text = "";
            txtTenNhanVien.Text = "";
            txtDienThoai.Text = "";
        }

       
    }
}
